package modes

import (
	"fmt"
)

/*
 * 描述：订单--协助报名
 *
 ********************************************************************************************/
type OrderSign struct {
	Id        int64  `json:"sig_id" xorm:"id" form:"-"`                                          // 订单ID
	Name      string `json:"sig_name" xorm:"name" form:"name" binding:"required"`                // 证书名称
	PId       int64  `json:"sig_pid" xorm:"pid" form:"pid" binding:"required"`                   // 订单ID
	PName     string `json:"sig_pname" xorm:"pname" form:"pname" binding:"required"`             // 项目名称
	UName     string `json:"sig_uname" xorm:"uname" form:"uname" binding:"required"`             // 学员姓名
	NUmberId  string `json:"sig_unmber_id" xorm:"number_id" form:"number_id" binding:"required"` // 身份证号
	Domicile  string `json:"sig_domicile" xorm:"domicile" form:"domicile" binding:"required"`    // 户籍地
	TestAdd   string `json:"sig_test_add" xorm:"test_add" form:"test_add" binding:"required"`    // 取证地
	OrderId   int64  `json:"sig_order_id" xorm:"order_id" form:"oid" binding:"required"`         // 订单ID
	RealPrice int64  `json:"sig_price" xorm:"real_price" form:"price" binding:"required"`        // 实付价格
}

func (this *OrderSign) TableName() string {
	return "order_sign"
}

func (this *OrderSign) Save() (int64, error) {
	return Db(2).Insert(this)
}

func (this *OrderSign) Where(fage, count, page int, where, field string) ([]OrderSign, error) {
	list := make([]OrderSign, 0)
	var err error
	if field == "" {
		field = "id"
	}
	page--
	if 0 == fage { // 从小到大排序
		err = Db(2).Table(this.TableName()).Where(where).
			Asc(field).
			Limit(count, page*count).
			Find(&list)
	} else { // 从大到小排序
		err = Db(2).Table(this.TableName()).Where(where).
			Desc(field).
			Limit(count, page*count).
			Find(&list)
	}
	return list, err
}

func (this *OrderSign) List(id int64) ([]OrderSign, error) {
	where := fmt.Sprintf("order_id = %d", id)
	list, err := this.Where(1, 10, 0, where, "")
	return list, err
}

func (this *OrderSign) ListByIds(ids []int64) ([]OrderSign, error) {
	list := make([]OrderSign, 0)
	err := Db(2).Table(this.TableName()).In("order_id", ids).Find(&list)
	return list, err
}
